package com.canin.dao;

import java.sql.Connection;
import java.sql.SQLException;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.sql.DataSource;

public class DAOFactory {
	
	public Connection connection = null;
	
	public void beginConnection() throws Exception
	{
		Context initContext = new InitialContext();
		Context envContext  = (Context)initContext.lookup("java:/comp/env");
		DataSource ds = (DataSource)envContext.lookup("jdbc/canin1");
		
		connection = ds.getConnection();
	}
	
	public void endConnection() throws SQLException
	{
		connection.close();
	}
	
	public void beginTransaction() throws SQLException
	{
		connection.setAutoCommit(false);
	}
	
	public void endTransaction() throws SQLException
	{
		try
		{
			connection.commit();
			connection.setAutoCommit(false);
		}
		catch( SQLException e )
		{
			connection.rollback();
		}
	}
	
	public AdminDAO createAdminDAO(){
		return new AdminDAO( connection );
	}
	
	public MemberDAO createMemberDAO(){
		return new MemberDAO( connection );
	}
	
	public BreedDAO createBreedDAO(){
		return new BreedDAO( connection );
	}
	
	public SizeDAO createSizeDAO()
	{
		return new SizeDAO( connection );
	}
	public DogDAO createDogDAO()
	{
		return new DogDAO( connection );
	}
	public FoodDAO createFoodDAO()
	{
		return new FoodDAO( connection );
	}
	public SEquipmentDAO createSEquipmentDAO()
	{
		return new SEquipmentDAO( connection );
	}
	public BedDAO createBedDAO()
	{
		return new BedDAO( connection );
	}
	
	public BowlDAO createBowlDAO()
	{
		return new BowlDAO( connection );
	}
	
	public KennelDAO createKennelDAO()
	{
		return new KennelDAO( connection );
	}
	
	public ToothbrushDAO createToothbrushDAO()
	{
		return new ToothbrushDAO( connection );
	}
	
	public LeashDAO createLeashDAO()
	{
		return new LeashDAO( connection );
	}
	
	public CollarDAO createCollarDAO()
	{
		return new CollarDAO( connection );
	}

	public ShampooDAO createShampooDAO()
	{
		return new ShampooDAO( connection );
	}
	
}
